package handlers

import (
	"code.google.com/p/jesus-1496/auth/sessionshelper"
	"code.google.com/p/jesus-1496/servererror"
	"code.google.com/p/jesus-1496/utils/env"
	"net/http"
)

//Handler that is used when the user logs in
func HomeHandler(w http.ResponseWriter, r *http.Request) *servererror.ServerError {
	user, err := sessionshelper.GetSessionUser(w, r)
	if err != nil {
		logger.Printf("homeHandler: handler called, but cannot get session user. Major shizzle gone down.")
		return servererror.NewServerError(err, "Internal server error.", http.StatusInternalServerError)
	}

	t, _, err := env.NewHtmlTemplateFromFile("home.html")
	if err != nil {
		return servererror.NewServerError(err, "Internal server error.", http.StatusInternalServerError)
	}
	w.Header().Set("Content-Type", "text/html")
	err = t.Execute(w, user)
	if err != nil {
		return servererror.NewServerError(err, "Internal server error.", http.StatusInternalServerError)
	}
	return nil
}
